/*
 * Server.cpp
 *
 *  Created on: 2011-03-22
 *      Author: kamil
 */

#include "Server.h"

#include <boost/archive/text_oarchive.hpp>
#include <boost/archive/binary_oarchive.hpp>

using namespace boost::asio;
using namespace std;

Server::Server(std::string ip, int port, boost::asio::io_service & svc)
	:  io_service(svc),
	multicastEndpoint(ip::address::from_string(ip), port),
	multicastSocket(io_service, multicastEndpoint.protocol())
{

}

Server::~Server() {

}

void Server::send(const GameStatePacket & packet){
	std::ostringstream oss;
	oss<<packet.cmd;
	oss<<packet.cmd_counter;
	oss<<packet.goals_blue;
	oss<<packet.goals_yellow;
	oss<<packet.time_remaining;
	string data = oss.str();

	std::vector<boost::asio::const_buffer> buffers;
	buffers.push_back(boost::asio::buffer(data));

	multicastSocket.send_to(buffers, multicastEndpoint);
}
